package com.anhuanjia.tools.eao.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.anhuanjia.tools.eao.bean.EaoQualification;
import com.efastsoft.framework.UIFacade;
import com.efastsoft.framework.annotation.Alias;
import com.efastsoft.framework.annotation.Priv;
import com.efastsoft.framework.annotation.Priv.LoginType;
import com.efastsoft.framework.data.DataRow;
import com.efastsoft.framework.data.DataTable;
import com.efastsoft.framework.data.Q;

/**
 *  机构资质表操作
 * @author Administrator
 *
 */
@Alias(value = "qualification" )
public class QualificationUI extends UIFacade {
	
	@Priv(loginType = LoginType.Member)
	public void findMune() {
		DataTable dt = new Q(" select * from eao_qualifications where Father = ' ' or Father is null ").fetch();
		List<Map<String, Object>> list = new ArrayList<>();
		for (DataRow dataRow : dt) {
			EaoQualification qualification = new EaoQualification();
			qualification.setValue(dataRow);
			Map<String, Object> qualificationVo = new HashMap<>();
			qualificationVo.put("value", qualification.getId());
			qualificationVo.put("label", qualification.getType());
			list.add(qualificationVo);
			List<Map<String, Object>> qualificationVo2List = new ArrayList<>();
			DataTable dt2 = new Q(" select * from eao_qualifications where Father = ? ORDER BY Num", qualification.getId()).fetch();
			if (dt2.getRowCount() > 0) {
				for (DataRow dataRow2 : dt2) {
					EaoQualification qualification2 = new EaoQualification();
					qualification2.setValue(dataRow2);
					Map<String, Object> qualificationVo2 = new HashMap<>();
					qualificationVo2.put("value", qualification2.getId());
					qualificationVo2.put("label", qualification2.getType());
					qualificationVo2List.add(qualificationVo2);
				}
			}
			if (!qualificationVo2List.isEmpty()) {
				qualificationVo.put("children", qualificationVo2List);
			}
			this.Response.put("data", list);
		}
	}
	
	@Priv(loginType = LoginType.Member)
	public void findQualifications() {
		DataTable qualificationTable = new Q(" select * from eao_qualifications ").fetch();
		List<EaoQualification> qualificationListTemp = new ArrayList<>();
		if (qualificationTable.getRowCount() != 0) {
			for (DataRow dataRow : qualificationTable) {
				EaoQualification qualification = new EaoQualification();
				qualification.setValue(dataRow);
				qualificationListTemp.add(qualification);
			}
			Map<String,Object> map = new HashMap<String,Object>(); 
			List<EaoQualification> AMap = new ArrayList<>();//甲级报告书评价范围
			List<EaoQualification> BMap = new ArrayList<>();//乙级报告书评价范围
			List<EaoQualification> CMap = new ArrayList<>();//报告表范围
			for (EaoQualification qualification : qualificationListTemp) {
				if("1".equals(qualification.getFather())){
					AMap.add(qualification);
				}else if("2".equals(qualification.getFather())){
					BMap.add(qualification);
				}else if("3".equals(qualification.getFather())){
					CMap.add(qualification);
				}
			}
			map.put("AMap", AMap);
			map.put("BMap", BMap);
			map.put("CMap", CMap);
			this.Response.put("map", map);
		}
	}
}
